package main.剑指OfferⅠ;

public class Day7 {
    public static void main(String[] args) {
        System.out.println("剑指Offer26.树的子结构");
        System.out.println("剑指Offer27.二叉树的镜像");
        System.out.println("剑指Offer28.对称的二叉树");
    }
}

class Offer26{
    public boolean process(TreeNode A, TreeNode B){
        if (B==null) return true;
        if (A==null) return false;
        return A.val==B.val&&process(A.left,B.left)&&process(A.right,B.right);
    }
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (B==null||A==null) return false;
        return process(A,B)||isSubStructure(A.left,B)||isSubStructure(A.right,B);
    }
}

class Offer27{
    public TreeNode process(TreeNode orgRoot){
        if (orgRoot==null) return null;
        TreeNode tempRoot=new TreeNode(orgRoot.val);
        tempRoot.left=process(orgRoot.right);
        tempRoot.right=process(orgRoot.left);
        return tempRoot;
    }
    public TreeNode mirrorTree(TreeNode root) {
        return process(root);
    }
}

class Offer28{
    public boolean process(TreeNode root1, TreeNode root2){
        if (root1==null&&root2==null) return true;
        if (root1!=null&&root2==null) return false;
        if (root1==null&&root2!=null) return false;
        return root1.val==root2.val&&process(root1.left,root2.right)&&process(root1.right,root2.left);
    }
    public boolean isSymmetric(TreeNode root) {
        return process(root,root);
    }
}